<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>map</title>
    <style>
    html { height:100% }
    body { height:100%; margin:0px; padding:0px }
    #iCenter { height:100% }
</style>
<link rel="stylesheet" href="/Public/Css/demo.Default.css" type="text/css" />
     <script language="javascript" src="http://api.amap.com/webapi/init?v=1.1"></script>
    <script language="javascript">

var mapObj,toolbar,overview,scale;

var lonlat_mouse;

var is_bus_sta = 0 ;

function mapInit()
{
    var opt = {
        level:8,//设置地图缩放级别
        center:new AMap.LngLat(116.397428,39.90923),//设置地图中心点
        doubleClickZoom:true,//双击放大地图
        scrollWheel:true//鼠标滚轮缩放地图
    }
    mapObj = new AMap.Map("iCenter",opt);
    mapObj.plugin(["AMap.ToolBar","AMap.OverView","AMap.Scale"],function()
    {
        toolbar = new AMap.ToolBar();
        toolbar.autoPosition=false; //加载工具条
        mapObj.addControl(toolbar);
        overview = new AMap.OverView(); //加载鹰眼
        mapObj.addControl(overview);
        scale = new AMap.Scale(); //加载比例尺
        mapObj.addControl(scale);
    });

    //右键菜单
    contextmenu = new AMap.ContextMenu();
    contextmenu.addItem("附近的公交站？",function(){
        //bus_line_search("110100011436", "010");
        is_bus_sta = 1;
        geocodeSearch();
        addMouseMarker(lonlat_mouse);
    },3);
    contextmenu.addItem("以此为终点",function(){
        //window.open("http://www.autonavi.com");
        geocodeSearch();
        var marker_end = new AMap.Marker({
                                             id:"zd",
                                             position:lonlat_mouse,
                                             icon:"http://api.amap.com/Home/Tpl/default/Public/Images/zd.png" ,
                                             offset:new AMap.Pixel(-15,-36)
                                         });
        mapObj.addOverlays(marker_end);
        mapObj.setCenter(lonlat_mouse);
        mainwindow.set_end_poi(lonlat_mouse.toString());
    },2);
    contextmenu.addItem("以此为起点",function(){
        //window.open("http://www.amap.com");
        geocodeSearch();
        var marker_start = new AMap.Marker({
                                               id:"qd",
                                               position:lonlat_mouse,
                                               icon:"http://api.amap.com/Home/Tpl/default/Public/Images/qd.png",
                                               offset:new AMap.Pixel(-15,-36)
                                           });
        mapObj.addOverlays(marker_start);
        mapObj.setCenter(lonlat_mouse);
        mainwindow.set_start_poi(lonlat_mouse.toString());
    },1);
    contextmenu.addItem("这是哪儿？",function(e){
        geocodeSearch();
        //alert("hello,world");
    },0);


    mapObj.bind(mapObj,"rightclick",function(e){
        lonlat_mouse = e.lnglat;
        //mainwindow.log(lonlat_mouse.toString());
        contextmenu.open(mapObj,e.lnglat);
    });

    bind();
}

function geocodeSearch(){
    //mainwindow.log("geocodeSearch");
    var xy= "1";  //document.getElementById("lnglat").value;
    if(xy==""){
        return;
    }else{
        //var coor=xy.split(",");
        //var lnglatXY=new AMap.LngLat(coor[0],coor[1])
        var GeocoderOption = {
            range:3000,//范围
            crossnum:0,//道路交叉口数
            roadnum :0,//路线记录数
            poinum:1//POI点数
        };
        var geo = new AMap.Geocoder(GeocoderOption);
        geo.regeocode(lonlat_mouse,poiToAddressSearch_CallBack);
        //addMouseMarker(lonlat_mouse);
        mapObj.setCenter(lonlat_mouse);
    }
    //mainwindow.log("geocodeSearch");
}

function addMouseMarker(lnglat){
    var marker=new AMap.Marker(
                {
                    id:"marker",
                    icon:"http://api.amap.com/webapi/static/Images/0.png",
                    position:lnglat,
                    offset:new AMap.Pixel(-15,-36)
                }
                );
    mapObj.addOverlays(marker);
    mapObj.setCenter(lnglat);
}

function poiToAddressSearch_CallBack(data){
    //mainwindow.log(JSON.stringify(data));
    var resultStr="";
    if(data.status =="E0")
    {
        //for(var i=0;i<data.list.length;i++){
        resultStr += "市："+ data.list[0].province.name +data.list[0].city.name+"<br/>";
        mainwindow.set_city_code(data.list[0].city.citycode);
        //for(var j=0;j<data.list[i].roadlist.length;j++){
        //    resultStr+="<br />道路："+data.list[i].roadlist[j].name+"&nbsp;&nbsp;<br />距离："+data.list[i].roadlist[j].distance+"<br />";
        //}
        //for (var j=0; j< data.list[i].poilist.length; j++) {
        resultStr += "名称："+data.list[0].poilist[0].name+"<br />地址："+data.list[0].poilist[0].address+"<br />类型："+data.list[0].poilist[0].type;
        //}
        //}
        if (is_bus_sta == 1)
        {
            var busstation = data.list[0].roadlist[0].name.split("(")[0];
            var citycode = data.list[0].city.citycode;
            StationSearch(busstation, citycode);
            is_bus_sta = 0 ;
        }
    }
    else if(data.status =="E1")
    {
        resultStr = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
    }
    else
    {
        resultStr= "错误信息："+data.state+"请对照API Server v2.0.0 简明提示码对照表查找错误类型";
    }
    //document.getElementById("result").innerHTML = resultStr;
    openInfo(resultStr);

}

function openInfo(info){
    var inforWindow = new AMap.InfoWindow({content:info});
    inforWindow.open(mapObj,lonlat_mouse);
}


function keywordSearch(){
    var lngX = document.getElementById("lngX").value;
    var latY = document.getElementById("latY").value;
    var centXY = new AMap.LngLat(lngX,latY);//中心点坐标
    var keywords = document.getElementById("keyword").value;//关键字
    var PoiSearchOption = {
        srctype:"POI",//数据来源
        type:"",//数据类别
        number:10,//每页数量,默认10
        batch:1,//请求页数，默认1
        range:7000, //查询范围，默认3000米
        ext:""//扩展字段
    };
    var MSearch = new AMap.PoiSearch(PoiSearchOption);
    //MSearch.byCenPoi(centXY,keywords,cenPoiSearch_func);
    //mainwindow.log("kw : " + kw);
    MSearch.byCenPoi(lonlat,kw,cenPoiSearch_func);
}

var resultCount=10;

var marker = new Array();

var windowsArr = new Array();

function addmarker(i,d){
    var markerOption = {
        icon:"http://api.amap.com/webapi/static/Images/"+(i+1)+".png",
        position:new AMap.LngLat(d.x,d.y)
    };
    var mar =new AMap.Marker(markerOption);
    mar.id=(i+1);
    marker.push(new AMap.LngLat(d.x,d.y));
    var infoWindow = new AMap.InfoWindow
            ({
                 content:"<h3><font color=\"#00a6ac\">&nbsp;&nbsp;"+(i+1) + "."+ d.name +"</h3></font>"+TipContents(d.type,d.address,d.tel),
                 size:new AMap.Size(300,0),     //设置信息窗口大小
                 autoMove:true,  //设置自动调整信息窗口至视野范围
                 offset:{x:-90,y:-65}
             });
    windowsArr.push(infoWindow);
    mapObj.addOverlays(mar);
    var aa=function(e){infoWindow.open(mapObj,mar.getPosition());};
    mapObj.bind(mar,"click",aa);
    var xx=function(e){console.log(e.lastLevel);}
    mapObj.bind(mapObj,"zoomchange",xx);
}

function cenPoiSearch_func(data){
    //mainwindow.log(JSON.stringify(data));
    mainwindow.poi_result_in(data);
    var resultStr="";
    if(data.status =="E0")
    {
        resultCount=data.list.length;
        for (var i = 0; i < data.list.length; i++) {
            //mainwindow.log(data.list[i].x + " , " + data.list[i].y);
            resultStr += "<div id='divid"+(i+1)+"' onmouseover='openMarkerTipById1("+i+",this)' onmouseout='onmouseout_MarkerStyle("+(i+1)+",this)' style=\"font-size: 12px;cursor:pointer;padding:2px 0 4px 2px; border-bottom:1px solid #C1FFC1;\"><table><tr><td><img src=\"http://api.amap.com/webapi/static/Images/"+(i+1)+".png\"></td>"+"<td><h3><font color=\"#00a6ac\">名称: "+data.list[i].name+"</font></h3>";
            resultStr += TipContents(data.list[i].type,data.list[i].address,data.list[i].tel)+"</td></tr></table></div>";
            addmarker(i,data.list[i]);
        }
        mapObj.setFitView();
    }
    else if(data.status =="E1")
    {
        resultStr = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
    }
    else
    {
        resultStr= "错误信息："+data.state+"请对照API Server v2.0.0 简明提示码对照表查找错误类型";
    }
    document.getElementById("result").innerHTML = resultStr;
}

function openMarkerTipById1(pointid,thiss){  //根据id打开搜索结果点tip
    thiss.style.background='#CAE1FF';
    windowsArr[pointid].open(mapObj,marker[pointid]);
}

function onmouseout_MarkerStyle(pointid,thiss) { //鼠标移开后点样式恢复
    thiss.style.background="";
}

function busSearch() {
    this.busSType = "s";
    //起始点
    this.cityname = "";
    this.start_x = "";
    this.start_y = "";
    this.start_name = "";
    this.start_address = "";
    this.start_tel = "";
    this.start_pid = "";
    this.start_citycode = "";
    this.start_cityname = "";
    this.start_detailLink = "";
    this.start_type = "";

    this.end_x = "";
    this.end_y = "";
    this.end_name = "";
    this.end_address = "";
    this.end_tel = "";
    this.end_pid = "";
    this.end_citycode = "";
    this.end_cityname = "";
    this.end_detailLink = "";
    this.end_type = "";
    this.x_array
    this.y_array
    this.x_c_array
    this.y_c_array
    this.xy_array
    this.xy_c_array
}

var busS = new busSearch();

function kkkeywordSearch() {
    busS.cityname = document.getElementById("city").value;
    busS.start_name = document.getElementById("keyword").value;
    busS.end_name = document.getElementById("keyword1").value;
    var i = 1;
    var che = "";
    if (busS.cityname == "") {
        che += i + "．请您输入城市\n";
        i = i + 1;
    }
    if (busS.start_name == "") {
        che += i + "．请您输入起点";
        i = i + 1;
    }
    if (busS.end_name == "") {
        che += i + "．请您输入终点";
        i = i + 1;
    }
    if (i == 1) {
        busS.busSType = "s";
        busChange_search(busS.cityname, busS.start_name);
    } else {

        alert(che);
    }
}

function busChange_search(keywords , city) {
    var PoiSearchOption = {
        number : 10, //每页数量
        batch : 1//请求页数
    };
    var MSearch = new AMap.PoiSearch(PoiSearchOption);
    MSearch.byKeywords(keywords, city, busChange_search_CallBack);
}

function busChange_search_CallBack(data) {
    if (busS.busSType == "s") {
        if (data.list == null) {
            document.getElementById("result").innerHTML = "起点未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
        } else {
            busS.start_x = data.list[0].x;
            busS.start_y = data.list[0].y;
            busS.start_name = data.list[0].name;
            busS.start_address = data.list[0].address;
            busS.start_tel = data.list[0].tel;
            busS.start_type = data.list[0].type;
            busS.start_pid = data.list[0].pguid;
            busS.start_citycode = data.list[0].citycode;
            buschange_EndSearch();

        }
    } else if (busS.busSType == "e") {

        if (data.status == "E1") {
            document.getElementById("result").innerHTML = "终点未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
        } else {
            busS.end_x = data.list[0].x;
            busS.end_y = data.list[0].y;
            busS.end_name = data.list[0].name;
            busS.end_address = data.list[0].address;
            busS.end_tel = data.list[0].tel;
            busS.end_type = data.list[0].type;
            busS.end_pid = data.list[0].pguid;
            busS.end_citycode = data.list[0].citycode;
            busChangeSearchXY();
        }
    }

}

function buschange_EndSearch() {

    busS.busSType = "e";
    busChange_search(busS.cityname, busS.end_name);

}

function bus_search(citycode) {
    //busS.start_x = 113.32228461;
    //busS.start_y = 23.1415644;
    //busS.end_x = 113.299865;
    //busS.end_y = 23.10103;
    var startXY = new AMap.LngLat(busS.start_x, busS.start_y);
    var endXY = new AMap.LngLat(busS.end_x, busS.end_y);
    //var startXY = new AMap.LngLat(113.32228461, 23.1415644);
    //var endXY = new AMap.LngLat(113.30490262 , 23.13425076);
    var mrs = new AMap.BusSearch(BusSearchOption);
    var BusSearchOption = {
        per : 100, //抽稀参数
        batch : 1, //当前页码
        number : 10//每页数量
    };
    var arr = new Array();
    //经纬度坐标数组
    arr.push(startXY);
    arr.push(endXY);
    var bus = new AMap.BusSearch(BusSearchOption);
    mrs.byTwoPoi(arr, citycode ,busChangeSearchXY_CallBack)
    mainwindow.log("bus search");
}

function busChangeSearchXY_CallBack(data) {
    mainwindow.log("bus search callback 1");
    mainwindow.bus_navi_result_in(data);
    busS.xy_array = new Array();
    busS.xy_c_array = new Array();
    var resultStr = "";
    if (data.status == "E0") {
        mainwindow.log("bus search callback 2");
        var bus_content = new Array();
        var bus_count = data.list.length;
        bus_content.push("<table width=\"340\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"2\" style=\"background:#e1e1e1;\">　线路</td><td width=\"181\" style=\" border-left:1px solid #fff; background:#e1e1e1;\">　乘车方案</td><td width=\"80\" style=\" border-left:1px solid #fff; background:#e1e1e1;\">　估计车程</td><td width=\"15\" style=\" background:#e1e1e1;\">&nbsp;</td></tr><tr><td colspan=\"5\">");
        for (var i = 0; i < bus_count; i++) {
            bus_content.push("<table width=\"350\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
            var bus_length = 0;
            var bus_name = "";
            var busxy = "";
            var busCHxy = "";
            var str_list = data.list[i].segmentList.length;
            //每次线路的换乘次数.
            var bus_text = "<tr style=\"background:#efefef;\"><td width=\"42\" align=\"center\"><img src=\"http://api.amap.com/webapi/static/Images/start.gif\" /></td><td colspan=\"3\">起点 " + data.list[i].segmentList[0].startName + "</td><td>&nbsp;</td></tr>";
            for (var k = 0; k < str_list; k++) {
                if (k == (str_list - 1)) {
                    bus_name += (data.list[i].segmentList[k].busName).split("(")[0];
                } else {
                    bus_name += (data.list[i].segmentList[k].busName).split("(")[0] + " <img src=\"http://api.amap.com/webapi/static/Images/supermap_arrow3.gif\" /> ";
                }//得到公交车名称.
                var passDepotName = (data.list[i].segmentList[k].passDepotName).split(" ");
                //对途经站点名称进行分隔.
                var passDepotNum = passDepotName.length + 1;

                bus_text += "<tr><td>&nbsp;</td><td colspan=\"2\">步行" + Getdistance(data.list[i].segmentList[k].footLength) + "到车站</td><td align=\"center\"><span style=\"color:#004a80;\">" + passDepotNum + "站</span></td><td>&nbsp;</td></tr><tr><td style=\" border-bottom:none;\">&nbsp;</td><td colspan=\"3\" style=\" border-bottom:none;\">" + data.list[i].segmentList[k].busName + "</td><td style=\" border-bottom:none;\">&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan=\"3\"><span class=\"gray\">在</span>　" + data.list[i].segmentList[k].startName + " <span class=\"gray\">上车</span>　<br />    <span class=\"gray\">在　</span>" + data.list[i].segmentList[k].endName + "　<span class=\"gray\">下车</span></td><td>&nbsp;</td></tr>";
                if (k == 0) {
                    var xy = (data.list[i].segmentList[k].coordinateList).split(";");
                    busCHxy += xy[xy.length - 1] + ";";
                } else if ((k + 1) != str_list) {
                    var xy = (data.list[i].segmentList[k].coordinateList).split(";");
                    busCHxy += xy[0] + ";" + xy[xy.length - 1] + ";";
                } else {
                    var xy = (data.list[i].segmentList[k].coordinateList).split(";");
                    busCHxy += xy[0] + ";";
                }
                busxy += data.list[i].segmentList[k].coordinateList + ";";
                if (str_list == 1) {
                    busCHxy = "";
                }//如果换乘次数为"1",没有换乘XY.此次线路可以直达.
                bus_length += parseInt(data.list[i].segmentList[k].driverLength);
                //每条线路车程
            }
            busS.xy_c_array[i] = busCHxy;
            busS.xy_array[i] = busxy;
            bus_content.push("<tr onclick=\"drawBuschangeLine('" + i + "')\" style=\"cursor:pointer\"><td colspan=\"3\" class=\"change_blue\">" + bus_name + "</td><td class=\"change_blue\">" + Getdistance(bus_length) + "</td><td class=\"change_blue\">&nbsp;</td></tr>" + bus_text + "<tr><td>&nbsp;</td><td colspan=\"3\">步行" + Getdistance(data.list[i].footEndLength) + "到终点<br /></td><td>&nbsp;</td></tr><tr style=\"background:#efefef;\"><td align=\"center\"><img src=\"http://api.amap.com/webapi/static/Images/end.gif\" /></td><td colspan=\"3\">终点 " + data.list[i].segmentList[str_list - 1].endName + "</td><td>&nbsp;</td></tr></table>");
            bus_content.push("<div style=\"height:0px;width:100%; line-height:0px;\"></div>");
        }
        bus_content.push("</td></tr></table>");
        resultStr = bus_content.join("");
        drawBuschangeLine('0');
        mainwindow.log("bus search callback 3");
    } else if (data.status == "E1") {
        mainwindow.log("bus search callback error");
        resultStr = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";

    } else {
        resultStr = "错误信息：" + data.state + "请对照API Server v2.0.0 简明提示码对照表查找错误类型!";
    }
    document.getElementById("result").innerHTML = resultStr;
    mapObj.setFitView();
    //mainwindow.log(resultStr);
}

function TipContents(type, address, tel) {
    if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {
        type = "暂无";
    }
    if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {
        address = "暂无";
    }
    if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {
        tel = "暂无";
    }
    var str = "<br />地址：" + address + "<br />电话：" + tel + " <br />类型：" + type;
    return str;
}

function Getdistance(le) {
    if (le <= 1000) {
        var s = le;
        return s + "米";
    } else {
        var s = Math.round(le / 1000);
        return "约" + s + "公里";
    }
}

function drawBuschangeLine(n) {
    var allover = new Array();
    var busxy = busS.xy_array[n].split(";");
    var busxy_n = busxy.length - 2;
    var busCHxy = busS.xy_c_array[n].split(";");
    var busCHxy_n = busCHxy.length - 1;

    var arrBus = new Array();
    for (var e = 0; e <= busxy_n; e++) {
        var xy = busxy[e].split(",");
        arrBus.push(new AMap.LngLat(xy[0], xy[1]));
    }
    var line = new AMap.Polyline({
                                     id : "polyline01",
                                     path : arrBus, //线经纬度数组
                                     strokeColor : "#005cb5", //线颜色
                                     strokeOpacity : 0.8, //线透明度
                                     strokeWeight : 6,  //线宽
                                     strokeStyle:"",//线样式
                                     strokeDasharray:[]//补充线样式
                                 });
    allover.push(line);
    /*换乘点之间的线*/

    if (busCHxy_n != 0) {
        var arrc = new Array();
        //alert(busS.xy_c_array[n]+"--"+busCHxy_n);
        for (var r = 0; r < 2; r++) {
            var xy = busCHxy[r].split(",");
            arrc.push(new AMap.LngLat(xy[0], xy[1]));
        }
        var changeline = new AMap.Polyline({
                                               path : arrc, //线经纬度数组
                                               strokeColor : "#6EB034", //线颜色
                                               strokeOpacity : 1, //线透明度
                                               strokeWeight : 6, //线宽
                                               strokeStyle:"",//线样式
                                               strokeDasharray:[],//补充线样式
                                               id : "changeline1"
                                           });
        allover.push(changeline);
        var arrc1 = new Array();
        if (busCHxy_n > 2) {
            for (var q = 2; q < 4; q++) {
                var xy = busCHxy[q].split(",");
                arrc1.push(new AMap.LngLat(xy[0], xy[1]));
            }
            var changeline1 = new AMap.Polyline({
                                                    path : arrc1, //线经纬度数组
                                                    strokeColor : "#6EB034", //线颜色
                                                    strokeOpacity : 1, //线透明度
                                                    strokeWeight : 6, //线宽
                                                    //strokeStyle:"dashed", //线样式
                                                    strokeStyle:"",//线样式
                                                    strokeDasharray:[],//补充线样式
                                                    id : "changeline2"
                                                });
        }
    }
    /*换乘点*/
    var temp = "";
    for (var r = 0; r < busCHxy_n; r++) {
        var xy = busCHxy[r].split(",");
        var change = new AMap.LngLat(xy[0], xy[1]);
        var changetmarker = new AMap.Marker({
                                                icon : "http://api.amap.com/webapi/static/Images/bx11.png", //复杂图标
                                                visible : true, //可见
                                                position : change,
                                                offset : {
                                                    x : -27,
                                                    y : -34
                                                }
                                            });
        changetmarker.id = busS.start_pid + "-" + r;
        allover.push(changetmarker);
    }
    /**/
    /*1起点到线的起点 2线的终点到终点*/
    var arr1 = new Array();
    arr1.push(new AMap.LngLat(busS.start_x, busS.start_y));
    var linestartxy = busxy[0].split(",");
    arr1.push(new AMap.LngLat(linestartxy[0], linestartxy[1]));
    var line1 = new AMap.Polyline({
                                      path : arr1, //线经纬度数组
                                      strokeColor : "#6EB034", //线颜色
                                      strokeOpacity : 0.8, //线透明度
                                      strokeWeight : 6, //线宽
                                      strokeStyle:"",//线样式
                                      strokeDasharray:[],//补充线样式
                                      id : "linestartline"
                                  });
    allover.push(line1);

    var arr2 = new Array();
    arr2.push(new AMap.LngLat(busS.end_x, busS.end_y));
    var lineendxy = busxy[busxy_n].split(",");
    arr2.push(new AMap.LngLat(lineendxy[0], lineendxy[1]));

    var line2 = new AMap.Polyline({
                                      path : arr2, //线经纬度数组
                                      strokeColor : "#6EB034", //线颜色
                                      strokeOpacity : 0.8, //线透明度
                                      strokeWeight : 6, //线宽
                                      strokeStyle:"",//线样式
                                      strokeDasharray:[],//补充线样式
                                      id : "lineendline"
                                  });
    allover.push(line2);
    /**/
    /*添加步行点*/
    var stepxy = busxy[0].split(",");
    var step = new AMap.LngLat(stepxy[0], stepxy[1]);
    var steptmarker = new AMap.Marker({
                                          icon : "http://api.amap.com/webapi/static/Images/bx.png", //复杂图标
                                          visible : true, //可见
                                          position : step,
                                          id : "steptmarker",
                                          offset : {
                                              x : -27,
                                              y : -34
                                          }
                                      });
    allover.push(steptmarker);

    var stepxy1 = busxy[busxy_n].split(",");
    var step1 = new AMap.LngLat(stepxy1[0], stepxy1[1]);
    var steptmarker1 = new AMap.Marker({
                                           icon : "http://api.amap.com/webapi/static/Images/bx.png", //复杂图标
                                           visible : true, //可见
                                           position : step1,
                                           id : "steptmarker1",
                                           offset : {
                                               x : -27,
                                               y : -34
                                           }
                                       });
    allover.push(steptmarker1);
    /*起点,终点*/
    var startmarker = new AMap.Marker({
                                          icon : "http://api.amap.com/webapi/static/Images/qd.png", //复杂图标
                                          visible : true, //可见
                                          position : new AMap.LngLat(busS.start_x, busS.start_y),
                                          id : busS.start_pid + "start",
                                          offset : {
                                              x : -15,
                                              y : -15
                                          }
                                      });
    var infoWindowS = new AMap.InfoWindow({
                                              content : "<font color=\"#00a6ac\">&nbsp;&nbsp;"+ busS.start_name +"</font>"+ TipContents(busS.start_type, busS.start_address, busS.start_tel),
                                              size : new AMap.Size(300, 0), //设置信息窗口大小
                                              autoMove : true
                                          });
    mapObj.bind(startmarker, "click", function(e) {
        infoWindowS.open(mapObj, startmarker.getPosition());
    });
    var endmarker = new AMap.Marker({
                                        icon : "http://api.amap.com/webapi/static/Images/zd.png", //复杂图标
                                        visible : true, //可见
                                        position : new AMap.LngLat(busS.end_x, busS.end_y),
                                        id : busS.end_pid + "end",
                                        offset : {
                                            x : -15,
                                            y : -15
                                        }
                                    });
    var infoWindowE = new AMap.InfoWindow({
                                              content : "<font color=\"#00a6ac\">&nbsp;&nbsp;"+ busS.end_name +"</font>"+ TipContents(busS.end_type, busS.end_address, busS.end_tel),
                                              size : new AMap.Size(300, 0), //设置信息窗口大小
                                              autoMove : true
                                          });
    mapObj.bind(endmarker, "click", function(e) {
        infoWindowE.open(mapObj, endmarker.getPosition());
    });
    allover.push(startmarker);
    allover.push(endmarker);

    mapObj.addOverlays(allover);
}

function routeSearch(){
    this.routeSType="s";//起始点
    this.cityname = "";
    this.start_x = "";this.start_y = "";this.start_name = "";this.start_address = "";this.start_tel = "";this.start_pid = "";this.start_citycode = "";this.start_cityname = "";this.start_detailLink="";this.start_type="";
    this.end_x = "";this.end_y = "";this.end_name = "";this.end_address = "";this.end_tel = "";this.end_pid = "";this.end_citycode = "";this.end_cityname = "";this.end_detailLink="";this.end_type="";
    this.x_array;this.y_array;this.x_c_array;this.y_c_array;
    this.xy_array;this.xy_c_array;
}

var routeS = new routeSearch();

function routeChangeSearchXY(route_type)
{
    var startXY= new AMap.LngLat(routeS.start_x,routeS.start_y);
    var endXY = new AMap.LngLat(routeS.end_x,routeS.end_y);
    var routeSearchOption={
        routeType:route_type,
    };
    var arr=new Array();//经纬度坐标数组
    arr.push(startXY);
    arr.push(endXY);
    var routeSearch = new  AMap.RouteSearch(routeSearchOption);
    routeSearch.getNaviPath(arr,routeChangeSearchXY_CallBack);
}

function routeChangeSearchXY_CallBack(data){
    //mainwindow.log(JSON.stringify(data));
    mainwindow.car_navi_result_in(data);
    mainwindow.log("routeChangeSearchXY_CallBack");
    var resultStr="";
    var route_count=data.count;
    var road_length = 0;
    if(data.status=="E0"){

        var route_text="";
        var route_length="";
        var route_content= new Array();
        routeS.xy_array=new Array();
        var arr = new Array();
        for(var i=0;i<route_count;i++){

            routeS.xy_array[i]=data.list[i].coor;  //每条线路的坐标

            if(i==0){
                route_text+="<tr id=\"tr_"+i+"\" onMouseover=\"driveLineDrawFoldline('"+i+"','"+route_count+"')\"  onMouseout=\"this.style.backgroundColor='';\" onclick=\"driveLineDrawFoldline_click('"+i+"','"+route_count+"')\"><td align=\"left\">"+(i+1)+". "+"<span class=\"gray\">沿</span><strong>"+data.list[i].roadName+"</strong>向<strong>"+data.list[i].direction+"</strong><span class=\"gray\">行驶</span>"+" "+data.list[i].roadLength+"</td></tr>";
            }
            else{
                route_text+="<tr id=\"tr_"+i+"\" onMouseover=\"driveLineDrawFoldline('"+i+"','"+route_count+"')\"  onMouseout=\"this.style.backgroundColor='';\" onclick=\"driveLineDrawFoldline_click('"+i+"','"+route_count+"')\"><td align=\"left\">"+(i+1)+". "+"<strong>"+data.list[i-1].action+"</strong>"+"<span class=\"gray\">进入</span><strong>"+data.list[i].roadName+"</strong>向<strong>"+data.list[i].direction+"</strong><span class=\"gray\">行驶</span>"+" "+data.list[i].roadLength+" "+"</td></tr>";
            }




            var allover = new Array();

            var poi_xy_r = data.list[i].coor.split(";");


            for(var j=0;j<poi_xy_r.length;j++){
                var arr_lnglat= new Array();
                arr_lnglat=poi_xy_r[j].split(",");
                arr.push(new AMap.LngLat(arr_lnglat[0],arr_lnglat[1])); }

        }

        var polyline=new AMap.Polyline(
                    {id:"polyline01",
                        path:arr,
                        strokeColor:"#F00",//线颜色
                        strokeOpacity:0.6,//线透明度
                        strokeWeight:5,//线宽
                        strokeStyle:"",//线样式
                        strokeDasharray:[]//补充线样式
                    });
        allover.push(polyline);

        var start = new AMap.LngLat(routeS.start_x,routeS.start_y);

        var marker_start = new AMap.Marker({
                                               id:"qd",
                                               position:start,
                                               icon:"http://api.amap.com/Home/Tpl/default/Public/Images/qd.png",
                                               offset:new AMap.Pixel(-15,-36)
                                           });

        allover.push(marker_start);

        var end = new AMap.LngLat(routeS.end_x,routeS.end_y);

        var marker_end = new AMap.Marker({
                                             id:"zd",
                                             position:end,
                                             icon:"http://api.amap.com/Home/Tpl/default/Public/Images/zd.png" ,
                                             offset:new AMap.Pixel(-15,-36)
                                         });
        allover.push(marker_end);
        mapObj.addOverlays(allover);
        mapObj.setFitView(allover);
        route_content.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ><tr><td style=\"background:#e1e1e1;\">路线</td></tr><tr><td><img src=\"http://code.mapabc.com/images/start.gif\" />起点："+routeS.start_name+"</td></tr>"+route_text+"<tr><td><img src=\"http://code.mapabc.com/images/end.gif\" />终点："+routeS.end_name+"</td></tr></table>");

        resultStr=route_content.join("");

    }
    else if(data.status!=E0){

        resultStr="没有找到搜索结果,请确保关键字是否正确。";
    }
    //document.getElementById("result").innerHTML = resultStr;
}


function StationSearch(busstation, citycode)
{
    //mainwindow.log("busstation" + busstation);
    mrs = new AMap.BusSearch(BusSearchOption);
    var BusSearchOption = {
        per : 100, //抽稀参数
        batch : 1, //当前页码
        number : 20//每页数量
    };
    mrs.byBusStation(busstation, citycode, stationNameSearch_CallBack);

}

function stationNameSearch_CallBack(data) {
    //mainwindow.log(JSON.stringify(data));
    mainwindow.bus_sta_result_in(data);
    mainwindow.log("stationNameSearch_CallBack");
    var resultStr ="";
    if(data.status == "E0") {
        resultCount=data.list.length;
        for(var i = 0; i < data.list.length; i++) {
            resultStr += "<div style=\"cursor:pointer;\" onclick=\"stationName("+i+")\" id=" + data.list[i].line_id + "> ► " + data.list[i].name + "</div><dl id=\"busline_id"+i+"\" style=\"display:none\">";
            if(data.list[i].company = "" || typeof data.list[i].company == undefined) {
                var company = "";
            } else {
                var company = "<dt>所属公司为：" + data.list[i].company + "</dt>";
            }
            if( typeof data.list.start_time == undefined) {
                var starttime = "";
            } else {
                var starttime = "<dt>起始时间为" + data.list[i].start_time.substring(0, 2) + ":" + data.list[i].start_time.substring(2, 4) + "</dt>";
            }
            if( typeof data.list.end_time == undefined) {
                var endtime = "";
            } else {
                var endtime = "<dt>结束时间为" + data.list[i].end_time.substring(0, 2) + ":" + data.list[i].end_time.substring(2, 4) + "</dt>";
            }
            if(typeof data.list[i].length==undefined) {
                var distance = "";
            }
            else {
                var distance = data.list[i].length;
            }
            if(data.list[i].air = "1") {
                air = "是";
            } else {
                air = "否";
            }
            if(data.list[i].type == "1") {
                type = "普通公交";
            } else if(data.list[i].type == "2") {
                type = "地铁";
            } else {
                type = "";
            }
            var content = company + starttime + endtime + "<dt>是否有空调："+air+"</dt>"+"<dt>驾车类型："+type+"</dt><dt>线路长度："+distance+"</dt>";
            resultStr += content;
            resultStr += "</dl>";


        }
        //document.getElementById("result").innerHTML = resultStr;
        //stationName(0);

    } else if(data.status == "E8008") {
        resultStr = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
        //document.getElementById("result").innerHTML = resultStr;
    } else {
        resultStr = "错误信息：" + data.status + "请对照 API Server v2.0.0 简明提示码对照表查找错误类型";
        //document.getElementById("result").innerHTML = resultStr;
    }

}

function BusLineSearch(){
    this.buslineID;this.busline_xy;this.busline_allpoi;this.buslin_pointid;//公交线路ID 公交线路XY 公交线路所有点信息 公交线路上点的ID
}

var busSL = new BusLineSearch();
var mrs_busline;

function bus_line_search(bbuslineID, bbusCity){
        busSL.buslineID = bbuslineID;
        busSL.busCity = bbusCity
        mrs_busline = new AMap.BusSearch(BusSearchOption);
        var BusSearchOption = {
            per:100,    //抽稀参数
            batch:1,//当前页码
            number:10//每页数量
        };
        mrs_busline.byBusId(busSL.buslineID,busSL.busCity,busIDSearch_CallBack);

}

function busIDSearch_CallBack(data){
    //mainwindow.car_navi_result_in(data);
    //mainwindow.log(JSON.stringify(data));
    mainwindow.log("busIDSearch_CallBack");
    mainwindow.bus_line_result_in(data);
    var resultStr="";
    if(data.status=="E0")
    {
        busSL.busline_xy = new Array();
        busSL.busline_poi = new Array();
        var lineNum = data.list.length;//返回线路总数.
        if(lineNum!=0){ //如果lineNum为0,没有返回任何线路.
            var bus_line_content = ""; var start_time = ""; end_time = "";
            for(var i=0;i<lineNum;i++){
                bus_line_content += "<div style=\"cursor:pointer;\" id=\"busline_table"+data.list[i].line_id+"\">   ► "+data.list[i].name+"</div><dl id=\"busline_id"+(i)+"\">";
                if(data.list[i].company =="" || typeof data.list[i].company == "undefined"){
                    var company="";
                }else{
                    var company = "<dt>所属公司："+data.list[i].company+"</dt>";
                }
                if(typeof data.list[i].start_time == "undefined"){
                    start_time="";
                }else{
                    start_time = data.list[i].start_time.substring(0,2)+":"+data.list[i].start_time.substring(2,4);
                }
                if(typeof data.list[i].end_time == "undefined"){
                    end_time="";
                }else{
                    end_time = data.list[i].end_time.substring(0,2)+":"+data.list[i].end_time.substring(2,4);
                }
                if(start_time == "" || end_time == ""){
                    bus_line_content += "<dt>全长："+data.list[i].length+"公里;"+company+"</dt>";
                }else{
                    bus_line_content += "<dt>首末车时间："+start_time+"-"+end_time+"；"+"全长："+data.list[i].length+"公里;"+company+"</dt>";
                }
                var stationName = new Array();
                var stationXY = new Array();
                var stationX = new Array();
                var stationY = new Array();
                var stationNum = new Array();
                for(var i=0; i<data.list.length;i++){
                    for(var j=0; j<data.list[i].stationdes.length;j++){
                        stationName.push(data.list[i].stationdes[j].name); //站点名称
                        stationXY.push(data.list[i].stationdes[j].xy); //站点经纬度坐标
                        stationX.push(data.list[i].stationdes[j].xy.split(",")[0]); //站点X
                        stationY.push(data.list[i].stationdes[j].xy.split(",")[1]); //站点Y
                        stationNum.push(data.list[i].stationdes[j].stationNum);//第几站
                    }
                    var poistr = "";
                    for(var a=0; a<data.list[i].stationdes.length;a++){
                        bus_line_content += "<dd class=\"busname\"><a href=\"javascript:drawSinglePoi('"+stationX[a]+"','"+stationY[a]+"','"+stationNum[a]+"','"+stationName[a]+"','"+data.list[i].name+"')\">"+stationNum[a]+"．"+stationName[a]+"</a></dd>"; //画站点
                        poistr += stationX[a]+";"+stationY[a]+";"+stationNum[a]+";"+stationName[a]+";"+data.list[0].name+","; //站点X,站点Y,第几站,站点名称.
                    }
                    bus_line_content+="</dl>";
                    busSL.busline_xy[data.list[i].line_id] =data.list[i].xys+ ";"; //线路xy.
                    busSL.busline_poi[data.list[i].line_id] = poistr; //线路所有站点信息并最后添加"-".
                }
            }
            resultStr+=bus_line_content;
            drawbusLine(data.list[0].line_id); //画线路
        }
        else if(data.status =="E1")
        {
            resultStr = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
        }
        else
        {
            resultStr= "错误信息："+data.state+"请对照API Server v2.0.0 简明提示码对照表查找错误类型";
        }
        //document.getElementById("result").innerHTML = resultStr;
        mapObj.setFitView();
    }
}

function clearOverlays(){
    mapObj.clearOverlays();
}

function drawbusLine(buslineID){
    var arr = new Array();
    var poi_xy = busSL.busline_xy[buslineID].split(";");
    var poilnglat = new Array();
    for(var e=0;e<poi_xy.length-1;e++){
        var poilnglat=poi_xy[e].split(",");
        arr.push(new AMap.LngLat(poilnglat[0],poilnglat[1]));
    }
    var polyline=new AMap.Polyline({
                                       id:"polyline01",
                                       path:arr,
                                       strokeColor:"#005cb5",      //线颜色
                                       strokeOpacity:0.8, //线透明度
                                       strokeWeight:6,  //线宽
                                       strokeStyle:"",//线样式
                                       strokeDasharray:[]//补充线样式
                                   });
    mapObj.addOverlays(polyline);
}

var info_busline,marker_busline=false;

//station x, station y, station number, station name, line name
function drawSinglePoi(px,py,serialid,pn,linename){
    info_busline = new AMap.InfoWindow();
    info_busline.setContent(pn+"<br>所属线路：" + linename + "<br>站点序号：第" + serialid + "站");
    info_busline.setOffset(new AMap.Pixel(-100,-65));
    var fn = function(e){
        info_busline.open(mapObj,marker_busline.getPosition());
    };
    if(marker){
        //如果点存在，则先卸去原事件
        mapObj.unbind(marker,"click",fn);
        mapObj.clearInfoWindow();
    }
    marker_busline = new AMap.Marker({
                                 icon:"http://api.amap.com/webapi/static/Images/point.png", //复杂图标
                                 visible:true, //可见
                                 position:new AMap.LngLat(px,py),
                                 offset:{x:-8,y:-9},
                                 id:"hj"
                             });
    mapObj.updateOverlay(marker_busline);
    mapObj.bind(marker_busline,"click",fn);

}

//定义事件回调函数
var fn = function(e){
        //mainwindow.log("JSON.stringify(e)");
        var map_xy = mapObj.getCenter().toString().split(",");
        mainwindow.set_map_xyz(map_xy[0], map_xy[1], mapObj.getZoom());
        //document.getElementById("c").innerHTML = e.type+" : "+e.lnglat.lng+","+e.lnglat.lat;
};
//事件绑定的方法
function bind(){
        mapObj.bind(mapObj,"dragend",fn);
        mapObj.bind(mapObj,"zoomchange",fn);
        mapObj.bind(mapObj,"resize",fn);
        //mapObj.bind(mapObj,"rightclick",fn);
}

function unbind(){
        //解绑时，回调函数要一致，否则不能解除绑定
        mapObj.clearbind();
}

    </script>
    </head>
    <body onload="mapInit();">
<!--    <table width="661px"  border="0" cellpadding="0" cellspacing="0">

        <tr>
            <td>--><div id="iCenter"></div><!--</td>-->
<!--            </tr>-->
<!--            <tr><td>-->
       <div style="display:none">  <b>经纬度：</b><input type="text" id="lngX" name="lngX" value="116.40546798706054" /> <input type="text" id="latY" value="39.90776109736608"/>&nbsp;<b>关键字：</b><input type="text" id="keyword" name="keyword" value="酒店" style="width:150px"/>&nbsp;<input type="button" value="查询" onclick="keywordSearch()""/></div>
<!--        </td></tr>-->
            <!--<tr><td>--><div style="display:none"><b>hdfhfjf:</b></div><!--</td></tr>-->
              <!--  <tr><td>--><div id="result" name="result" style="display:none"></div>
           </div><!--</td>-->
  <!--     </tr>
    </table>-->
    </body>
    </html>
